package com.hxzy.facade.controller.admin;

import com.github.pagehelper.PageInfo;
import com.hxzy.framework.common.exception.ApiException;
import com.hxzy.framework.common.resp.R;
import com.hxzy.framework.common.resp.ResultCode;
import com.hxzy.module.admin.api.AdminFeignApi;
import com.hxzy.module.admin.api.role.req.*;
import com.hxzy.module.admin.api.role.resp.AdminRoleResp;
import com.hxzy.module.admin.api.role.resp.RoleAuthorityTreeResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Objects;

/**
 * @Author wy
 * @Description 后台用户管理
 * @Date 2024/1/31 14:19
 * @Version 1.0
 */
@RestController
@Api(tags = "总店后台-后台用户管理")
@RequestMapping("/role")
public class AdminRoleController {

    @Autowired
    private AdminFeignApi adminFeignApi;

    @ApiOperation(value = "角色列表", notes = "角色列表")
    @GetMapping(value = "/roleList")
    public R<PageInfo<AdminRoleResp>> roleList(@Validated AdminRoleReq req) {
        return this.adminFeignApi.adminRoleList(req);
    }



    @ApiOperation(value = "角色详情", notes = "角色详情")
    @GetMapping(value = "/roleDetail/{roleId}")
    public R<AdminRoleResp> roleDetail( @PathVariable(value = "roleId") Long roleId) {
        return this.adminFeignApi.adminRoleDetail(roleId);
    }

    /**
     * 根据角色id返回权限树
     * @param roleId
     * @return
     */
    @ApiOperation(value = "角色ID还原权限树", notes = "角色ID还原权限树")
    @GetMapping(value = "/roleAuthorityTree/{roleId}")
    public R<List<RoleAuthorityTreeResp>> roleAuthorityTree(@PathVariable(value = "roleId") Long roleId){
       return this.adminFeignApi.roleAuthorityTree(roleId);
    }

    @ApiOperation(value = "新增角色", notes = "新增角色")
    @PostMapping(value = "/addRole")
    public R addRole(@RequestBody @Valid AdminRoleAddReq req){
       return this.adminFeignApi.addRole(req);
    }

    @ApiOperation(value = "编辑角色", notes = "编辑角色")
    @PutMapping(value = "/editRole")
    public R editRole(@RequestBody @Valid AdminRoleEditReq req){
        return this.adminFeignApi.editRole(req);
    }

    @ApiOperation(value = "修改角色权限", notes = "修改角色权限")
    @PutMapping(value = "/changeRoleAuthority")
    public R changeRoleAuthority(@RequestBody @Valid ChangeRoleAuthorityReq req){
      return this.adminFeignApi.changeRoleAuthority(req);
    }

    /**
     * 修改角色状态
     * @param req
     * @return
     */
    @ApiOperation(value = "修改角色状态", notes = "修改角色状态")
    @PutMapping(value = "/changeRoleState")
    public R changeRoleState(@RequestBody @Valid ChangeRoleStateReq req){
        return this.adminFeignApi.changeRoleState(req);
    }

    @ApiOperation(value = "删除角色", notes = "删除角色")
    @DeleteMapping(value = "/delRole/{roleId}")
    public R  delRole(@PathVariable(value = "roleId") Long roleId){
        return this.adminFeignApi.delRole(roleId);
    }

}
